package com.example.demospringmybatisplus.service;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 调用远程服务异常降级处理类
 *
 * @DATE 2024/5/8
 **/
@Slf4j
@Component
@Aspect
public class DataExceptionDegradeHandler {

    @Around("execution(* com.example.demospringmybatisplus.processors.DataOperationService.findList(..))")
    public Object degrade(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("Around,注解方式实现aop服务降级----");
        try {
            // 模拟调用远程服务异常
            int i = 1 / 0;
            return joinPoint.proceed();
        } catch (Exception e) {
            // 调用远程服务异常，改为从本地或其它地方获取业数据
            System.out.println("调用远程服务异常，这里模拟从其它地方获取业务数据");
            return 1;
        }
    }
}
